{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "J:\\MyInstall\\anaconda3.6\\lib\\site-packages\\h5py\\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  from ._conv import register_converters as _register_converters\n"
     ]
    }
   ],
   "source": [
    "\"\"\"A very simple MNIST classifier.\n",
    "See extensive documentation at\n",
    "https://www.tensorflow.org/get_started/mnist/beginners\n",
    "\"\"\"\n",
    "from __future__ import absolute_import\n",
    "from __future__ import division\n",
    "from __future__ import print_function\n",
    "\n",
    "import argparse\n",
    "import sys\n",
    "\n",
    "from tensorflow.examples.tutorials.mnist import input_data\n",
    "\n",
    "import tensorflow as tf\n",
    "\n",
    "FLAGS = None\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Extracting /tmp/tensorflow/mnist/input_data\\train-images-idx3-ubyte.gz\n",
      "Extracting /tmp/tensorflow/mnist/input_data\\train-labels-idx1-ubyte.gz\n",
      "Extracting /tmp/tensorflow/mnist/input_data\\t10k-images-idx3-ubyte.gz\n",
      "Extracting /tmp/tensorflow/mnist/input_data\\t10k-labels-idx1-ubyte.gz\n"
     ]
    }
   ],
   "source": [
    "# 下载mnist数据\n",
    "# Import data\n",
    "data_dir = '/tmp/tensorflow/mnist/input_data'\n",
    "mnist = input_data.read_data_sets(data_dir, one_hot=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def weight_variable(shape):\n",
    "    initial = tf.truncated_normal(shape, stddev=0.1)\n",
    "    return tf.Variable(initial)\n",
    "\n",
    "def bias_variable(shape):\n",
    "    initial = tf.constant(0.1, shape=shape)\n",
    "    return tf.Variable(initial)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "#x = tf.placeholder(tf.float32, [784])\n",
    "#x = tf.placeholder(tf.float32, [784, 784])\n",
    "x = tf.placeholder(\"float\", shape=[None, 784])\n",
    "y_ = tf.placeholder(tf.float32, [None, 10])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<tf.Tensor 'Placeholder:0' shape=(?, 784) dtype=float32>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def conv2d(x, W):\n",
    "    return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')\n",
    "\n",
    "def max_pool_2x2(x):\n",
    "    return tf.nn.max_pool(x, ksize=[1, 2, 2, 1], strides=[1, 2, 2,1], padding='SAME')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "with tf.name_scope('reshape'):\n",
    "    x_image = tf.reshape(x, [-1, 28, 28, 1])\n",
    "\n",
    "with tf.name_scope('conv1'):\n",
    "    W_conv1 = weight_variable([5, 5, 1, 32])\n",
    "    b_conv1 = bias_variable([32])\n",
    "    h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)\n",
    "with tf.name_scope('pool1'):  \n",
    "    h_pool1 = max_pool_2x2(h_conv1)\n",
    "    \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "with tf.name_scope('conv2'):\n",
    "    W_conv2 = weight_variable([5, 5, 32, 64])\n",
    "    b_conv2 = bias_variable([64])\n",
    "    h_conv2 = tf.nn.relu(conv2d(h_pool1, W_conv2) + b_conv2)\n",
    "    \n",
    "with tf.name_scope('pool2'): \n",
    "    h_pool2 = max_pool_2x2(h_conv2)\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "with tf.name_scope('fc1'):\n",
    "    W_fc1 = weight_variable([7 * 7 * 64, 1024])\n",
    "    b_fc1 = bias_variable([1024])\n",
    "    h_pool2_flat = tf.reshape(h_pool2,[-1,7*7*64])\n",
    "    h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "with tf.name_scope('dropout'):\n",
    "    keep_prob = tf.placeholder(\"float\")\n",
    "    h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "with tf.name_scope('fc2'):\n",
    "    W_fc2 = weight_variable([1024, 10])\n",
    "    b_fc2 = bias_variable([10])\n",
    "    y_conv=tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2)\n",
    "#y_conv=(tf.matmul(h_fc1_drop, W_fc2) + b_fc2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "cross_entropy = -tf.reduce_sum(y_*tf.log(y_conv))\n",
    "train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)\n",
    "# sess = tf.Session()\n",
    "# correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y_,1))\n",
    "# accuracy = tf.reduce_mean(tf.cast(correct_prediction, \"float\"))\n",
    "# sess.run(tf.initialize_all_variables())\n",
    "# for i in range(20000):\n",
    "#     batch = mnist.train.next_batch(50)\n",
    "#     if i%100 == 0:\n",
    "#         train_accuracy = accuracy.eval(feed_dict={ x:batch[0], y_: batch[1], keep_prob: 1.0})\n",
    "#         print (\"step␣%d,␣training␣accuracy%g\"%(i, train_accuracy))\n",
    "#         train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob:0.5})\n",
    "#         print (\"test␣accuracy␣%g\"%accuracy.eval(feed_dict={x: mnist.test.images, y_: mnist.test.labels, keep_prob: 1.0}))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# cross_entropy = -tf.reduce_sum(y_*tf.log(y_conv))\n",
    "\n",
    "# global_step = tf.Variable(0, trainable=False)\n",
    "\n",
    "# starter_learning_rate = 1.0\n",
    "\n",
    "# cross_entropy = (tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y_conv)))\n",
    "\n",
    "# learning_rate = tf.train.exponential_decay(starter_learning_rate, global_step, 1000, 0.9, staircase=True)\n",
    "\n",
    "# train_step = tf.train.GradientDescentOptimizer(learning_rate=learning_rate).minimize(cross_entropy,global_step)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0:  0.094300\n",
      "100:  0.740400\n",
      "200:  0.852300\n",
      "300:  0.891700\n",
      "400:  0.910200\n",
      "500:  0.922100\n",
      "600:  0.929500\n",
      "700:  0.942000\n",
      "800:  0.944000\n",
      "900:  0.952000\n",
      "1000:  0.953500\n",
      "1100:  0.954600\n",
      "1200:  0.958500\n",
      "1300:  0.960600\n",
      "1400:  0.963100\n",
      "1500:  0.962500\n",
      "1600:  0.966400\n",
      "1700:  0.964900\n",
      "1800:  0.967200\n",
      "1900:  0.968500\n",
      "2000:  0.970100\n",
      "2100:  0.971400\n",
      "2200:  0.971000\n",
      "2300:  0.971800\n",
      "2400:  0.971000\n",
      "2500:  0.974100\n",
      "2600:  0.974100\n",
      "2700:  0.976100\n",
      "2800:  0.975400\n",
      "2900:  0.976700\n",
      "3000:  0.977400\n",
      "3100:  0.977600\n",
      "3200:  0.978400\n",
      "3300:  0.978100\n",
      "3400:  0.979000\n",
      "3500:  0.979200\n",
      "3600:  0.978300\n",
      "3700:  0.982100\n",
      "3800:  0.978900\n",
      "3900:  0.982300\n",
      "4000:  0.979400\n",
      "4100:  0.980900\n",
      "4200:  0.981700\n",
      "4300:  0.981500\n",
      "4400:  0.981700\n",
      "4500:  0.982000\n",
      "4600:  0.981800\n",
      "4700:  0.982100\n",
      "4800:  0.982200\n",
      "4900:  0.982100\n",
      "5000:  0.984900\n",
      "5100:  0.980000\n",
      "5200:  0.983800\n",
      "5300:  0.983000\n",
      "5400:  0.982200\n",
      "5500:  0.983100\n",
      "5600:  0.983800\n",
      "5700:  0.982800\n",
      "5800:  0.985500\n",
      "5900:  0.983400\n",
      "6000:  0.984400\n",
      "6100:  0.983600\n",
      "6200:  0.983900\n",
      "6300:  0.984100\n",
      "6400:  0.985300\n",
      "6500:  0.984200\n",
      "6600:  0.984300\n",
      "6700:  0.985000\n",
      "6800:  0.987100\n",
      "6900:  0.986300\n",
      "7000:  0.985100\n",
      "7100:  0.983200\n",
      "7200:  0.985500\n",
      "7300:  0.986200\n",
      "7400:  0.984900\n",
      "7500:  0.986200\n",
      "7600:  0.987500\n",
      "7700:  0.985300\n",
      "7800:  0.987900\n",
      "7900:  0.987300\n",
      "8000:  0.985900\n",
      "8100:  0.986700\n",
      "8200:  0.987600\n",
      "8300:  0.986900\n",
      "8400:  0.985100\n",
      "8500:  0.986100\n",
      "8600:  0.986000\n",
      "8700:  0.987100\n",
      "8800:  0.986100\n",
      "8900:  0.986400\n",
      "9000:  0.987800\n",
      "9100:  0.987900\n",
      "9200:  0.985800\n",
      "9300:  0.987900\n",
      "9400:  0.987700\n",
      "9500:  0.987900\n",
      "9600:  0.987400\n",
      "9700:  0.986800\n",
      "9800:  0.986600\n",
      "9900:  0.986000\n",
      "10000:  0.986000\n",
      "10100:  0.986900\n",
      "10200:  0.989000\n",
      "10300:  0.987000\n",
      "10400:  0.987200\n",
      "10500:  0.987100\n",
      "10600:  0.987600\n",
      "10700:  0.988600\n",
      "10800:  0.987900\n",
      "10900:  0.987500\n",
      "11000:  0.989100\n",
      "11100:  0.989300\n",
      "11200:  0.988400\n",
      "11300:  0.989300\n",
      "11400:  0.987800\n",
      "11500:  0.987100\n",
      "11600:  0.990200\n",
      "11700:  0.987800\n",
      "11800:  0.987900\n",
      "11900:  0.987700\n",
      "12000:  0.987700\n",
      "12100:  0.989100\n",
      "12200:  0.987800\n",
      "12300:  0.988900\n",
      "12400:  0.988400\n",
      "12500:  0.987900\n",
      "12600:  0.988700\n",
      "12700:  0.988600\n",
      "12800:  0.989100\n",
      "12900:  0.988600\n",
      "13000:  0.987500\n",
      "13100:  0.989300\n",
      "13200:  0.988600\n",
      "13300:  0.988900\n",
      "13400:  0.989100\n",
      "13500:  0.988700\n",
      "13600:  0.989000\n",
      "13700:  0.988200\n",
      "13800:  0.987400\n",
      "13900:  0.989500\n",
      "14000:  0.987900\n",
      "14100:  0.988500\n",
      "14200:  0.988200\n",
      "14300:  0.988400\n",
      "14400:  0.988100\n",
      "14500:  0.989000\n",
      "14600:  0.990200\n",
      "14700:  0.988900\n",
      "14800:  0.989000\n",
      "14900:  0.989500\n",
      "15000:  0.988100\n",
      "15100:  0.989300\n",
      "15200:  0.988400\n",
      "15300:  0.989800\n",
      "15400:  0.988500\n",
      "15500:  0.989200\n",
      "15600:  0.988000\n",
      "15700:  0.988700\n",
      "15800:  0.989000\n",
      "15900:  0.989500\n",
      "16000:  0.990400\n",
      "16100:  0.988200\n",
      "16200:  0.989400\n",
      "16300:  0.990200\n",
      "16400:  0.988300\n",
      "16500:  0.988800\n",
      "16600:  0.988600\n",
      "16700:  0.989200\n",
      "16800:  0.989000\n",
      "16900:  0.990000\n",
      "17000:  0.990200\n",
      "17100:  0.988500\n",
      "17200:  0.988600\n",
      "17300:  0.989100\n",
      "17400:  0.990500\n",
      "17500:  0.989300\n",
      "17600:  0.990500\n",
      "17700:  0.990300\n",
      "17800:  0.989600\n",
      "17900:  0.988600\n",
      "18000:  0.988100\n",
      "18100:  0.989600\n",
      "18200:  0.989500\n",
      "18300:  0.989000\n",
      "18400:  0.988700\n",
      "18500:  0.990000\n",
      "18600:  0.988300\n",
      "18700:  0.990200\n",
      "18800:  0.989600\n",
      "18900:  0.990200\n",
      "19000:  0.990800\n",
      "19100:  0.989100\n",
      "19200:  0.989600\n",
      "19300:  0.989300\n",
      "19400:  0.989500\n",
      "19500:  0.990200\n",
      "19600:  0.990400\n",
      "19700:  0.988600\n",
      "19800:  0.990200\n",
      "19900:  0.989700\n",
      "20000:  0.990800\n",
      "20100:  0.989200\n",
      "20200:  0.991300\n",
      "20300:  0.098000\n",
      "20400:  0.098000\n",
      "20500:  0.098000\n",
      "20600:  0.098000\n",
      "20700:  0.098000\n",
      "20800:  0.098000\n",
      "20900:  0.098000\n",
      "21000:  0.098000\n",
      "21100:  0.098000\n",
      "21200:  0.098000\n",
      "21300:  0.098000\n",
      "21400:  0.098000\n",
      "21500:  0.098000\n",
      "21600:  0.098000\n",
      "21700:  0.098000\n",
      "21800:  0.098000\n",
      "21900:  0.098000\n",
      "22000:  0.098000\n",
      "22100:  0.098000\n",
      "22200:  0.098000\n",
      "22300:  0.098000\n",
      "22400:  0.098000\n",
      "22500:  0.098000\n",
      "22600:  0.098000\n",
      "22700:  0.098000\n",
      "22800:  0.098000\n",
      "22900:  0.098000\n",
      "23000:  0.098000\n",
      "23100:  0.098000\n",
      "23200:  0.098000\n",
      "23300:  0.098000\n",
      "23400:  0.098000\n",
      "23500:  0.098000\n",
      "23600:  0.098000\n",
      "23700:  0.098000\n",
      "23800:  0.098000\n",
      "23900:  0.098000\n",
      "24000:  0.098000\n",
      "24100:  0.098000\n",
      "24200:  0.098000\n",
      "24300:  0.098000\n",
      "24400:  0.098000\n",
      "24500:  0.098000\n",
      "24600:  0.098000\n",
      "24700:  0.098000\n",
      "24800:  0.098000\n",
      "24900:  0.098000\n",
      "25000:  0.098000\n",
      "25100:  0.098000\n",
      "25200:  0.098000\n",
      "25300:  0.098000\n",
      "25400:  0.098000\n",
      "25500:  0.098000\n",
      "25600:  0.098000\n",
      "25700:  0.098000\n",
      "25800:  0.098000\n",
      "25900:  0.098000\n",
      "26000:  0.098000\n",
      "26100:  0.098000\n",
      "26200:  0.098000\n",
      "26300:  0.098000\n",
      "26400:  0.098000\n",
      "26500:  0.098000\n",
      "26600:  0.098000\n",
      "26700:  0.098000\n",
      "26800:  0.098000\n",
      "26900:  0.098000\n",
      "27000:  0.098000\n",
      "27100:  0.098000\n",
      "27200:  0.098000\n",
      "27300:  0.098000\n",
      "27400:  0.098000\n",
      "27500:  0.098000\n",
      "27600:  0.098000\n",
      "27700:  0.098000\n",
      "27800:  0.098000\n",
      "27900:  0.098000\n",
      "28000:  0.098000\n",
      "28100:  0.098000\n",
      "28200:  0.098000\n",
      "28300:  0.098000\n",
      "28400:  0.098000\n",
      "28500:  0.098000\n",
      "28600:  0.098000\n",
      "28700:  0.098000\n",
      "28800:  0.098000\n",
      "28900:  0.098000\n",
      "29000:  0.098000\n",
      "29100:  0.098000\n",
      "29200:  0.098000\n",
      "29300:  0.098000\n",
      "29400:  0.098000\n",
      "29500:  0.098000\n",
      "29600:  0.098000\n",
      "29700:  0.098000\n",
      "29800:  0.098000\n",
      "29900:  0.098000\n",
      "30000:  0.098000\n",
      "30100:  0.098000\n",
      "30200:  0.098000\n",
      "30300:  0.098000\n",
      "30400:  0.098000\n",
      "30500:  0.098000\n",
      "30600:  0.098000\n",
      "30700:  0.098000\n",
      "30800:  0.098000\n",
      "30900:  0.098000\n",
      "31000:  0.098000\n",
      "31100:  0.098000\n",
      "31200:  0.098000\n",
      "31300:  0.098000\n",
      "31400:  0.098000\n",
      "31500:  0.098000\n",
      "31600:  0.098000\n",
      "31700:  0.098000\n",
      "31800:  0.098000\n",
      "31900:  0.098000\n",
      "32000:  0.098000\n",
      "32100:  0.098000\n",
      "32200:  0.098000\n",
      "32300:  0.098000\n",
      "32400:  0.098000\n",
      "32500:  0.098000\n",
      "32600:  0.098000\n",
      "32700:  0.098000\n",
      "32800:  0.098000\n",
      "32900:  0.098000\n",
      "33000:  0.098000\n",
      "33100:  0.098000\n",
      "33200:  0.098000\n",
      "33300:  0.098000\n",
      "33400:  0.098000\n",
      "33500:  0.098000\n",
      "33600:  0.098000\n",
      "33700:  0.098000\n",
      "33800:  0.098000\n",
      "33900:  0.098000\n",
      "34000:  0.098000\n",
      "34100:  0.098000\n",
      "34200:  0.098000\n",
      "34300:  0.098000\n",
      "34400:  0.098000\n",
      "34500:  0.098000\n",
      "34600:  0.098000\n",
      "34700:  0.098000\n",
      "34800:  0.098000\n",
      "34900:  0.098000\n",
      "35000:  0.098000\n",
      "35100:  0.098000\n",
      "35200:  0.098000\n",
      "35300:  0.098000\n",
      "35400:  0.098000\n",
      "35500:  0.098000\n",
      "35600:  0.098000\n",
      "35700:  0.098000\n",
      "35800:  0.098000\n",
      "35900:  0.098000\n",
      "36000:  0.098000\n",
      "36100:  0.098000\n",
      "36200:  0.098000\n",
      "36300:  0.098000\n",
      "36400:  0.098000\n",
      "36500:  0.098000\n",
      "36600:  0.098000\n",
      "36700:  0.098000\n",
      "36800:  0.098000\n",
      "36900:  0.098000\n",
      "37000:  0.098000\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-14-6614494b5343>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      8\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m50000\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      9\u001b[0m     \u001b[0mbatch_xs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbatch_ys\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmnist\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtrain\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnext_batch\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m100\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 10\u001b[1;33m     \u001b[0msess\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtrain_step\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeed_dict\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mbatch_xs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my_\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mbatch_ys\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkeep_prob\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m0.5\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     11\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mi\u001b[0m \u001b[1;33m%\u001b[0m \u001b[1;36m100\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     12\u001b[0m         \u001b[0mcorrect_prediction\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mequal\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0margmax\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my_conv\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0margmax\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my_\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mJ:\\MyInstall\\anaconda3.6\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36mrun\u001b[1;34m(self, fetches, feed_dict, options, run_metadata)\u001b[0m\n\u001b[0;32m    903\u001b[0m     \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    904\u001b[0m       result = self._run(None, fetches, feed_dict, options_ptr,\n\u001b[1;32m--> 905\u001b[1;33m                          run_metadata_ptr)\n\u001b[0m\u001b[0;32m    906\u001b[0m       \u001b[1;32mif\u001b[0m \u001b[0mrun_metadata\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    907\u001b[0m         \u001b[0mproto_data\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtf_session\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mTF_GetBuffer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrun_metadata_ptr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mJ:\\MyInstall\\anaconda3.6\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_run\u001b[1;34m(self, handle, fetches, feed_dict, options, run_metadata)\u001b[0m\n\u001b[0;32m   1135\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mfinal_fetches\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mfinal_targets\u001b[0m \u001b[1;32mor\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mhandle\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mfeed_dict_tensor\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1136\u001b[0m       results = self._do_run(handle, final_targets, final_fetches,\n\u001b[1;32m-> 1137\u001b[1;33m                              feed_dict_tensor, options, run_metadata)\n\u001b[0m\u001b[0;32m   1138\u001b[0m     \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1139\u001b[0m       \u001b[0mresults\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mJ:\\MyInstall\\anaconda3.6\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_do_run\u001b[1;34m(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)\u001b[0m\n\u001b[0;32m   1353\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mhandle\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1354\u001b[0m       return self._do_call(_run_fn, self._session, feeds, fetches, targets,\n\u001b[1;32m-> 1355\u001b[1;33m                            options, run_metadata)\n\u001b[0m\u001b[0;32m   1356\u001b[0m     \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1357\u001b[0m       \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_do_call\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_prun_fn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_session\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mhandle\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeeds\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfetches\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mJ:\\MyInstall\\anaconda3.6\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_do_call\u001b[1;34m(self, fn, *args)\u001b[0m\n\u001b[0;32m   1359\u001b[0m   \u001b[1;32mdef\u001b[0m \u001b[0m_do_call\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1360\u001b[0m     \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1361\u001b[1;33m       \u001b[1;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1362\u001b[0m     \u001b[1;32mexcept\u001b[0m \u001b[0merrors\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mOpError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1363\u001b[0m       \u001b[0mmessage\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcompat\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mas_text\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmessage\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mJ:\\MyInstall\\anaconda3.6\\lib\\site-packages\\tensorflow\\python\\client\\session.py\u001b[0m in \u001b[0;36m_run_fn\u001b[1;34m(session, feed_dict, fetch_list, target_list, options, run_metadata)\u001b[0m\n\u001b[0;32m   1338\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1339\u001b[0m           return tf_session.TF_Run(session, options, feed_dict, fetch_list,\n\u001b[1;32m-> 1340\u001b[1;33m                                    target_list, status, run_metadata)\n\u001b[0m\u001b[0;32m   1341\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1342\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_prun_fn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msession\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mhandle\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfeed_dict\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfetch_list\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "\n",
    "init = tf.global_variables_initializer()\n",
    "# 定义Session\n",
    "sess = tf.Session()\n",
    "# 执行变量的初始化\n",
    "sess.run(init)\n",
    "\n",
    "for i in range(50000):\n",
    "    batch_xs, batch_ys = mnist.train.next_batch(100)\n",
    "    sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys, keep_prob:0.5})\n",
    "    if i % 100 == 0:\n",
    "        correct_prediction = tf.equal(tf.argmax(y_conv, 1), tf.argmax(y_, 1))\n",
    "\n",
    "        accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))\n",
    "\n",
    "        print(\"%d:  %f\"%(i,sess.run(accuracy, feed_dict={x: mnist.test.images,\n",
    "                                      y_: mnist.test.labels, keep_prob:0.5})))\n",
    " \n",
    "    \n",
    " "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
